#include "PointLight.h"
#include "Scene.h"

LightSample PointLight::L(const Scene * scene, const Vector3 & position, const Vector3 & normal) const {
	Vector3 dir = this->position - position;
	Double rSqr = dir.lengthSqr();
	Double r = sqrt(rSqr);
	dir /= r;

	Color shadowColor = Colors::White;
	if (shadow)
		scene->traceShadow(Ray(position, dir), shadowColor, r);

	Float attenuation = Float(1.0 / rSqr);
	return LightSample(strength *= attenuation *= shadowColor *= illuminance, dir);
}
